//handles google wave data
jsDM = new function _jsDM()
{
	this.id = "jsDM";
	this.vals = new Object();
	this.isIdle = true;
	this.callbacks = new Object();
	this.delta = _jsDMDelta;
	this.registerCallback = _jsDMRegisterCallback;
	this.processData = _jsDMprocessData;
	
}
//set interval
setInterval(_jsDMidleSubmit,1000);

function _jsDMidleSubmit()
{
	if(jsDM.isIdle)
	{
		var bHasValues = false;
		//build objects in CSV
		var out="<ul>";
		for(var type in jsDM.vals)
		{
			bHasValues=true;
			out+="<li>" + type + "<ul>";
			for(var obj in jsDM.vals[type])
			{
				
				out+="<li>" + obj + "<ul>";
				for(var _key in jsDM.vals[type][obj])
				{
					out+= _key + ": " + jsDM.vals[type][obj][_key];
				}
				out+="</ul></li>";
			}
			out+="</ul></li>";
		}
		out+="</ul>";
		if(bHasValues)
		{
			jsDebug.Throw(jsDM.id,255,out);
			delete jsDM.vals;
			jsDM.vals = new Object();
		}
		//wave.submitDelta();
		
	}
	jsDM.isIdle = true;
}

function _jsDMDelta(obj,key,val)
{
	this.isIdle = false;
	if(!obj.id)
	{
		//throw hard error
		jsDebug.Throw(this.id,0,"Object: " + obj + " does not have an id.");
		return;
	}
	if(!obj.type)
	{
		jsDebug.Throw(this.id,0,"Object: " + obj + " does not have a defined type.");
		return;
	}
	if(!this.vals[obj.type])
	{
		this.vals[obj.type] = new Object();
	}
	if(!this.vals[obj.type][obj.id])
	{
		this.vals[obj.type][obj.id]= new Object();
	}
	
	if(this.vals[obj.type][obj.id][key])
	{
		//throw soft message
		jsDebug.Throw(this.id,255,"Overwriting existing key: " + obj.id + "," + key);
	}
	this.vals[obj.type][obj.id][key] = val;
	
}

function _jsDMRegisterCallback(key,fun)
{
	this.callbacks[key] = fun;
}

function _jsDMprocessData()
{
	
}

